<template>
    <div class="login-wraper">
        <div class="top">
            <img src="https://preview.pro.antdv.com/assets/logo.f3103225.svg" alt="">
            <h1>Ant Design</h1>
        </div>

        <div class="desc">
            {{$t('message.desc')}}
        </div>

        <div class="user-from">
            <div class="login-form" v-if="!showRegisterWraper">
                <a-tabs default-active-key="1">
                    <a-tab-pane key="1" :tab="$t('message.loginAccount')">
                        <a-form :form="form" :label-col="{ span: 5 }" :wrapper-col="{ span: 24 }">
                            <a-form-item>
                                <a-input :placeholder="$t('message.account') +': admin'" size="large"
                                    v-decorator="['account', { rules: [{ required: true, message: '请输入账户名或邮箱地址!' }] }]">
                                    <a-icon slot="prefix" type="user" />
                                </a-input>
                            </a-form-item>
                            <a-form-item>
                                <a-input-password :placeholder="$t('message.password') +': admin or ant.design'"
                                    @keyup.enter.native="handleSubmit" size="large" autocomplete="new-password"
                                    v-decorator="['password', { rules: [{ required: true, message: '请输入密码!' }] }]">
                                    <a-icon slot="prefix" type="lock" />
                                    <LockOutlined />
                                </a-input-password>
                            </a-form-item>
                        </a-form>
                    </a-tab-pane>
                    <a-tab-pane key="2" :tab="$t('message.loginByPhone')" force-render>
                        <a-form :form="phoneForm" :label-col="{ span: 5 }" :wrapper-col="{ span: 24 }">
                            <a-form-item>
                                <a-input :placeholder="$t('message.phone')" size="large" autocomplete="off"
                                    v-decorator="['phone', { rules: [{ required: true, message: '手机号' }] }]">
                                    <a-icon slot="prefix" type="mobile" />
                                </a-input>
                            </a-form-item>
                            <a-form-item>
                                <a-row>
                                    <a-col :xs="16" :sm="16" :md="16" :lg="16" :xl="16">
                                        <a-input-password :placeholder="$t('message.code')" size="large"
                                            autocomplete="new-password"
                                            v-decorator="['code', { rules: [{ required: true, message: '请输入验证码!' }] }]">
                                            <a-icon slot="prefix" type="mail" />
                                            <LockOutlined />
                                        </a-input-password>
                                    </a-col>
                                    <a-col :xs="7" :sm="7" :md="7" :lg="7" :xl="7" :push="1">
                                        <a-button style="width: 100%;font-size: 14px;" size="large"
                                            @click="getValidateCode">
                                            {{$t('message.getCode')}}
                                        </a-button>
                                    </a-col>
                                </a-row>
                            </a-form-item>
                        </a-form>
                    </a-tab-pane>
                </a-tabs>

                <div class="form-box">
                    <div class="form-box-item">
                        <a-checkbox @change="onChange">
                            {{$t('message.autoLofin')}}
                        </a-checkbox>
                        <a href="javascript:void;">{{$t('message.forgetPassword')}}</a>
                    </div>
                </div>
                <a-button type="primary" size="large" style="width: 100%;" @click="handleSubmit"
                    :loading="submitLoading">
                    {{$t('message.loginBtn')}}
                </a-button>
            </div>

            <div class="register-wraper" v-if="showRegisterWraper">
                <div class="title">注册</div>
                <a-form :form="form" :label-col="{ span: 5 }" :wrapper-col="{ span: 24 }">
                    <a-form-item>
                        <a-input :placeholder="$t('message.account') +': admin'" size="large"
                            v-decorator="['account', { rules: [{ required: true, message: '请输入账户名或邮箱地址!' }] }]">
                            <a-icon slot="prefix" type="user" />
                        </a-input>
                    </a-form-item>
                    <a-form-item>
                        <a-input-password :placeholder="$t('message.password') +': admin or ant.design'" size="large"
                            autocomplete="new-password"
                            v-decorator="['password', { rules: [{ required: true, message: '请输入密码!' }] }]">
                            <a-icon slot="prefix" type="lock" />
                            <LockOutlined />
                        </a-input-password>
                    </a-form-item>
                </a-form>
            </div>

            <div class="other-login-way">
                <span>{{$t('message.otherLoginWay')}}
                    <a-icon type="alipay-circle" />
                    <a-icon type="taobao-circle" />
                    <a-icon type="weibo-circle" />
                </span>
                <a @click="showRegisterWraper = !showRegisterWraper"
                    href="javascript:void;">{{$t('message.register')}}</a>
            </div>

            <div class="bottom">
                <div>
                    <span>{{$t('message.help')}}</span>
                    <span>{{$t('message.privacy')}}</span>
                    <span>{{$t('message.clause')}}</span>
                </div>
                <div>Copyright © 2018 vueComponent</div>
            </div>
        </div>

        <div class="globl">
            <languageComponent></languageComponent>
        </div>
    </div>
</template>

<script>

    import languageComponent from '../components/language-switch';

    export default {
        name: 'loginC',
        components: {
            languageComponent,
        },
        data() {
            return {
                showRegisterWraper: false,
                formLayout: 'horizontal',
                form: this.$form.createForm(this, { name: 'coordinated' }),
                phoneForm: this.$form.createForm(this, { name: 'coordinated' }),
                submitLoading: false
            };
        },
        methods: {
            handleSubmit(e) {
                this.submitLoading = true;
                e.preventDefault();
                this.form.validateFields((err, values) => {
                    if (!err) {
                        if (values.account === 'admin' && values.password === 'admin') {
                            this.$router.push('dashboard');
                        } else {
                            this.$message.error('账号或密码错误！')
                        }
                    }
                });
                setTimeout(() => {
                    this.submitLoading = false;
                }, 1000)
            },
            handleSelectChange(value) {
                console.log(value);
                this.form.setFieldsValue({
                    note: `Hi, ${value === 'male' ? 'man' : 'lady'}!`,
                });
            },
            getValidateCode() {

            },
            onChange() {

            },
        },

        mounted() {
            this.$i18n.locale = localStorage.getItem('language') || 'cn';
        }
    }

</script>

<style scoped lang="less">
    .login-wraper {
        width: 100%;
        height: 100%;
        background: url(https://preview.pro.antdv.com/assets/background.5825f033.svg);
        background-size: cover;
        background-color: #f0f2f5;
        overflow: auto;

        .top {
            display: flex;
            padding-top: 70px;
            align-items: center;
            justify-content: center;

            img {
                width: 44px;
                margin-right: 16px;
            }

            h1 {
                font-size: 33px;
                color: rgba(0, 0, 0, .85);
                font-family: Avenir, Helvetica Neue, Arial, Helvetica, sans-serif;
                font-weight: 600;
                margin-bottom: 0;
            }
        }

        .desc {
            font-size: 14px;
            color: rgba(0, 0, 0, .45);
            margin-top: 12px;
            margin-bottom: 40px;
            text-align: center;
        }

        .user-from {
            min-width: 260px;
            width: 368px;
            margin: 0 auto;

            ::v-deep .ant-tabs-nav-scroll {
                display: flex;
                justify-content: center;
            }

            ::v-deep .ant-tabs-bar {
                border: none;
            }

            ::v-deep .anticon {
                color: #999;
            }

            ::v-deep .ant-btn-loading {
                background-color: #f0f2f5;
                border-color: #f0f2f5;
            }

            .form-box {
                margin-bottom: 30px;
                margin-top: 10px;

                .form-box-item {
                    display: flex;
                    justify-content: space-between;
                    margin-bottom: 20px;
                }

            }

            .other-login-way {
                display: flex;
                justify-content: space-between;
                align-items: center;
                padding-top: 30px;
                font-size: 14px;

                span {
                    display: flex;
                    align-items: center;
                }

                .anticon {
                    margin-left: 16px;
                    font-size: 24px;
                    cursor: pointer;
                    color: rgba(0, 0, 0, .2);
                    transition: color .3s;

                    &:hover {
                        color: #1890ff;
                    }
                }
            }

            .bottom {
                width: 58%;
                margin: 0 auto;
                margin-top: 40px;
                color: rgba(0, 0, 0, .45);

                div:nth-child(1) {
                    display: flex;
                    justify-content: space-between;
                    margin-bottom: 10px;
                    padding: 0 20px;
                }
            }

            .register-wraper {
                .title {
                    margin-bottom: 22px;
                    font-size: 18px;
                }
            }
        }

        .globl {
            position: fixed;
            right: 20px;
            top: 20px;
            font-size: 24px;
        }
    }
</style>